package SortHelper;

import java.util.Arrays;

public class SortHelper {
    private SortHelper() {
    }

    //判断数组是否有序
    public static <E extends Comparable<E>> boolean isSorted(E[] arr) {
        for (int i = 1; i < arr.length; i++) {
            if (arr[i - 1].compareTo(arr[i]) > 0) {
                return false;
            }
        }
        return true;
    }

    //交换数组中两个元素
    public static <E> void swap(E[] arr, int i, int j) {
        E t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }

    //打印数组，用了java自带的方法，艹
    public static <E> void printArr(E[] arr){
        System.out.println(Arrays.toString(arr));
    }
}
